//
// Decompiled by Jadx - 520ms
//
package p;

import aa.f;
import ed.a;
import ed.d;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import kotlin.collections.k;
import kotlin.jvm.internal.i;
import okhttp3.ad;
import okhttp3.ae;
import okhttp3.q;
import okhttp3.s;
import okhttp3.t;
import okhttp3.u;
import okhttp3.w;
import okhttp3.z;

public abstract class c implements u {
    public t a;

    public abstract TreeMap<String, Object> b(TreeMap<String, Object> treeMap);

    public final ae c(f fVar) throws IOException {
        LinkedHashMap eu;
        k unmodifiableMap;
        z.a aVar;
        q d;
        LinkedHashMap eu2;
        k unmodifiableMap2;
        String str;
        z zVar = fVar.f;
        boolean equals = "GET".equals(zVar.c);
        s sVar = zVar.d;
        Map map = zVar.f;
        t tVar = zVar.b;
        if (equals) {
            this.a = t.m(a.d(tVar.l));
            t.a s = tVar.s();
            ArrayList arrayList = new ArrayList(tVar.t());
            TreeMap<String, Object> treeMap = new TreeMap<>();
            for (int i = 0; i < arrayList.size(); i++) {
                List u = tVar.u((String) arrayList.get(i));
                if (u.size() > 0) {
                    str = (String) u.get(0);
                } else {
                    str = "";
                }
                treeMap.put((String) arrayList.get(i), str);
            }
            String obj = Collections.singletonList(arrayList).toString();
            TreeMap<String, Object> b = b(treeMap);
            String str2 = d.a;
            for (Map.Entry<String, Object> entry : b.entrySet()) {
                String valueOf = String.valueOf(entry.getValue());
                if (!obj.contains(entry.getKey())) {
                    s.i(entry.getKey(), valueOf);
                }
            }
            t j = s.j();
            new LinkedHashMap();
            String str3 = zVar.c;
            ad adVar = zVar.e;
            if (map.isEmpty()) {
                eu2 = new LinkedHashMap();
            } else {
                eu2 = kotlin.collections.d.eu(map);
            }
            s e = sVar.e().e();
            byte[] bArr = l.c.a;
            if (eu2.isEmpty()) {
                unmodifiableMap2 = kotlin.collections.d.el();
            } else {
                unmodifiableMap2 = Collections.unmodifiableMap(new LinkedHashMap(eu2));
                i.e(unmodifiableMap2, "Collections.unmodifiableMap(LinkedHashMap(this))");
            }
            zVar = new z(j, str3, e, adVar, unmodifiableMap2);
        } else if ("POST".equals(zVar.c)) {
            this.a = tVar;
            q qVar = zVar.e;
            if (qVar instanceof q) {
                q.a aVar2 = new q.a();
                q qVar2 = qVar;
                TreeMap<String, Object> treeMap2 = new TreeMap<>();
                for (int i2 = 0; i2 < qVar2.b.size(); i2++) {
                    t.b bVar = t.b;
                    treeMap2.put(t.b.e(bVar, (String) qVar2.b.get(i2), 0, 0, true, 3), t.b.e(bVar, (String) qVar2.c.get(i2), 0, 0, true, 3));
                }
                TreeMap<String, Object> b2 = b(treeMap2);
                String str4 = d.a;
                for (Map.Entry<String, Object> entry2 : b2.entrySet()) {
                    aVar2.d(entry2.getKey(), String.valueOf(entry2.getValue()));
                }
                a.c(a.d(this.a.x().toString()), b2);
                d = new q(aVar2.a, aVar2.b);
                aVar = new z.a(zVar);
            } else if (qVar instanceof w) {
                w.a aVar3 = new w.a();
                aVar3.e(w.b);
                ArrayList arrayList2 = new ArrayList(((w) qVar).i);
                for (Map.Entry<String, Object> entry3 : b(new TreeMap<>()).entrySet()) {
                    arrayList2.add(w.c.d(entry3.getKey(), String.valueOf(entry3.getValue())));
                }
                Iterator it = arrayList2.iterator();
                while (it.hasNext()) {
                    w.c cVar = (w.c) it.next();
                    i.f(cVar, "part");
                    aVar3.c.add(cVar);
                }
                d = aVar3.d();
                aVar = new z.a(zVar);
            } else if (qVar instanceof ad) {
                String c = a.c(a.d(this.a.x().toString()), b(new TreeMap<>()));
                aVar = new z.a(zVar);
                aVar.l(c);
                zVar = aVar.g();
            }
            aVar.j("POST", d);
            zVar = aVar.g();
        } else {
            new LinkedHashMap();
            String str5 = zVar.c;
            ad adVar2 = zVar.e;
            if (map.isEmpty()) {
                eu = new LinkedHashMap();
            } else {
                eu = kotlin.collections.d.eu(map);
            }
            s.a e2 = sVar.e();
            if (tVar != null) {
                s e3 = e2.e();
                byte[] bArr2 = l.c.a;
                if (eu.isEmpty()) {
                    unmodifiableMap = kotlin.collections.d.el();
                } else {
                    unmodifiableMap = Collections.unmodifiableMap(new LinkedHashMap(eu));
                    i.e(unmodifiableMap, "Collections.unmodifiableMap(LinkedHashMap(this))");
                }
                zVar = new z(tVar, str5, e3, adVar2, unmodifiableMap);
            } else {
                throw new IllegalStateException("url == null".toString());
            }
        }
        return fVar.k(zVar);
    }
}
